#include "item.h"

item::item(QString name) {
	this->name = name;
	memset(this->val, 0, sizeof(val));
	memset(this->rank, 0, sizeof(rank));
}
item::item() {

}
item::~item() {

}
QString item::getName() {
	return this->name;
}
void item::setName(QString name) {
	this->name = name;
}
int* item::getVal() {
	return this->val;
}

void item::swapVal(int m,int n) {
	int temp;
	temp = val[m];
	val[m] = val[n];
	val[n] = temp;
}

void item::setVal(int index, int value) {
	this->val[index] = value;
}
//闃熶紞鎺掑悕
int* item::getRank() {
	return this->rank;
}
void item::setRank(int index,int rank) {
	this->rank[index] = rank;
}
int boyItem::cnt = 0;
int girlItem::cnt = 0;
int boyItem::type = 1;
int girlItem::type = 0;
QJsonObject item::toJsonObject () {
	QJsonObject obj;

	// 序列化基类属性
	obj["name"] = getName();

	// 序列化数组值
	const int* values = getVal();
	QJsonArray valArray;
	for (int i = 0; i < N; i++) {
		valArray.append(values[i]);
	}
	obj["val"] = valArray;
	const int* ranks = getRank();
	QJsonArray rankArray;
	for (int i = 0; i < N; i++) {
		rankArray.append(ranks[i]);
	}
	obj["rank"] = rankArray;
	return obj;
}
QJsonObject boyItem::toJsonObject(){
	QJsonObject obj;

	// 序列化基类属性
	obj["name"] = getName();

	// 序列化数组值
	const int* values = getVal();
	QJsonArray valArray;
	for (int i = 0; i < N; i++) {
		valArray.append(values[i]);
	}
	obj["val"] = valArray;
	const int* ranks = getRank();
	QJsonArray rankArray;
	for (int i = 0; i < N; i++) {
		rankArray.append(ranks[i]);
	}
	obj["rank"] = rankArray;
	// 序列化派生类属性
	obj["type"] = getType();

	return obj;
}
QJsonObject girlItem::toJsonObject() {
	QJsonObject obj;

	// 序列化基类属性
	obj["name"] = getName();

	// 序列化数组值
	const int* values = getVal();
	QJsonArray valArray;
	for (int i = 0; i < N; i++) {
		valArray.append(values[i]);
	}
	obj["val"] = valArray;
	// 序列化数组值
	const int* ranks = getRank();
	QJsonArray rankArray;
	for (int i = 0; i < N; i++) {
		rankArray.append(ranks[i]);
	}
	obj["rank"] = rankArray;
	// 序列化派生类属性
	obj["type"] = getType();

	return obj;
}
